﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace MetaHeuristics.Aco
{
    using MetaHeuristics.Collections;

    public class BestImprovementTwoOptLocalSearch : BaseTwoOptLocalSearch
    {
        public override void Search()
        {
            foreach (Ant ant in this.Aco.Ants)
                this.Search(ant);
        }

        protected override void Search(Ant ant)
        {
            float delta;
            for (int i = 1; i < this.Aco.Cities.Count-1; i++)
            {
                for (int j = i + 1; j < this.Aco.Cities.Count-1; j++)
                {
                    if (j == i + 1 || i == j + 1)
                        continue;
                    delta = IfSwapElements(ant, i, j);
                    if (delta < 0)
                    {
                        ant.Tours.Swap(i, j);
                        ant.Tours.Length += delta;
                        float length = this.Aco.Distances.ComputeTourLength(ant.Tours);
                    }
                }
            }
        }
    }
}
